package main

import "fmt"

func main() {

	var number [5]int
	for i := 0; i < len(number); i++ {
		number[i] = i + 1
	}

	// 遍历数组1 for...len()
	//foreach1(number)

	// 遍历数组2 for i,v := range
	foreach2(number) // 1 2 3 4 5

	// 注意,函数作为参数,进行修改元素中的值,原数组不会改变
	//modifyArray(number)
	//foreach2(number) // 1 2 3 4 5

	//number[2] = 10
	//foreach2(number) // 1 2 10 4 5
}

func modifyArray(number [5]int) {
	number[2] = 10
}

func foreach2(number [5]int) {
	for _, v := range number {
		//fmt.Print("下标:",i) // 下划线  匿名变量
		fmt.Print(" 值:", v)
		fmt.Print(" ")
	}
}

func foreach1(number [5]int) {
	for i := 0; i < len(number); i++ {
		fmt.Print(number[i])
	}
}
